﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation.Attributes;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Validators.Record;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Models.Price;
using System.ComponentModel;
using Sahit.iSoilHotel.ServiceProxy.Tavern.Models.Customer;
using Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Models.Room;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;

namespace Sahit.iSoilHotel.Portal.ServiceProxy.Tavern.Models.Record
{
    [Validator(typeof(CheckInValidator))]
    public class CheckInModel:RecordModel
    {
        public CheckInModel()
        {
            SexOptions = new List<SelectListItem>(){
                new SelectListItem(){Value="m",Text="Male",Selected = true},
                new SelectListItem(){Value="f",Text="Female"}};

            StartDate = DateTime.Now;
            EndDate = DateTime.Now.AddDays(1);
            Room = new RoomModel();

            Customers = new List<CustomerModel>();

            Price = new PriceModel() { };
            PriceCode = new PriceCodeModel() { ID = new Guid("77C388D3-D858-4B02-88E0-11DC4BE40E75"), Code = "full" };
        }

        public IList<SelectListItem> SexOptions { get; set; }
        public IList<SelectListItem> RoomTypeOptions { get; set; }
        public IList<SelectListItem> PriceCodeOptions { get; set; }

        public void SetRoomTypeOptions(List<RoomTypeModel> roomTypeModes)
        {
            var q = from r in roomTypeModes.AsEnumerable()
                    select new SelectListItem() { Text = r.Name, Value = r.ID.ToString() };
            RoomTypeOptions = q.ToList();
        }

        public void SetPriceCodeOptions(List<PriceCodeModel> priceCodeModes)
        {
            var q = from r in priceCodeModes.AsEnumerable()
                    select new SelectListItem() { Text = r.Code, Value = r.ID.ToString() };
            PriceCodeOptions = q.ToList();
        }

        [DisplayName("Start Date")]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
        [UIHint("DateNullable")]
        public override DateTime StartDate { get; set; }

        [DisplayName("End Date")]
        [UIHint("DateNullable")]
        public override DateTime EndDate { get; set; }
    }
}
